/*   1:    */ package org.intellij.plugins.relaxNG.model.resolve;
/*   2:    */ 
/*   3:    */

import com.intellij.ide.highlighter.XmlFileType;
import com.intellij.openapi.fileTypes.FileType;
import com.intellij.openapi.vfs.VirtualFile;
import com.intellij.psi.impl.include.FileIncludeInfo;
import com.intellij.psi.impl.include.FileIncludeProvider;
import com.intellij.util.Consumer;
import com.intellij.util.indexing.FileContent;
import com.intellij.util.text.CharArrayUtil;
import com.intellij.util.xml.NanoXmlUtil;
import com.intellij.util.xml.NanoXmlUtil.IXMLBuilderAdapter;
import org.intellij.plugins.relaxNG.compact.RncFileType;
import org.intellij.plugins.relaxNG.compact.psi.RncElement;
import org.intellij.plugins.relaxNG.compact.psi.RncElementVisitor;
import org.intellij.plugins.relaxNG.compact.psi.RncInclude;
import org.jetbrains.annotations.NotNull;

import java.util.ArrayList;

/*   4:    */
/*   5:    */
/*   6:    */
/*   7:    */
/*   8:    */
/*   9:    */
/*  10:    */
/*  11:    */
/*  12:    */
/*  13:    */
/*  14:    */
/*  15:    */
/*  16:    */
/*  17:    */
/*  18:    */
/*  19:    */
/*  20:    */ 
/*  21:    */ public class RelaxIncludeProvider
/*  22:    */   extends FileIncludeProvider
/*  23:    */ {
/*  24:    */   @NotNull
/*  25:    */   public String getId()
/*  26:    */   {
/*  27: 30 */     String tmp2_0 = "relax-ng";
/*  28: 30 */     if (tmp2_0 == null) {
/*  29: 30 */       throw new IllegalStateException(String.format("@NotNull method %s.%s must not return null", new Object[] { "org/intellij/plugins/relaxNG/model/resolve/RelaxIncludeProvider", "getId" }));
/*  30:    */     }
/*  31: 30 */     return tmp2_0;
/*  32:    */   }
/*  33:    */   
/*  34:    */   public boolean acceptFile(VirtualFile paramVirtualFile)
/*  35:    */   {
/*  36: 35 */     FileType localFileType = paramVirtualFile.getFileType();
/*  37: 36 */     return (localFileType == XmlFileType.INSTANCE) || (localFileType == RncFileType.getInstance());
/*  38:    */   }
/*  39:    */   
/*  40:    */   public void registerFileTypesUsedForIndexing(@NotNull Consumer<FileType> paramConsumer)
/*  41:    */   {
/*  42: 41 */     if (paramConsumer == null) {
/*  43: 41 */       throw new IllegalArgumentException(String.format("Argument %s for @NotNull parameter of %s.%s must not be null", new Object[] { "0", "org/intellij/plugins/relaxNG/model/resolve/RelaxIncludeProvider", "registerFileTypesUsedForIndexing" }));
/*  44:    */     }
/*  45: 41 */     paramConsumer.consume(XmlFileType.INSTANCE);
/*  46: 42 */     paramConsumer.consume(RncFileType.getInstance());
/*  47:    */   }
/*  48:    */   
/*  49:    */   @NotNull
/*  50:    */   public FileIncludeInfo[] getIncludeInfos(FileContent paramFileContent)
/*  51:    */   {
/*  52:    */     final ArrayList localArrayList;
/*  53: 50 */     if (paramFileContent.getFileType() == XmlFileType.INSTANCE)
/*  54:    */     {
/*  55: 51 */       CharSequence localCharSequence = paramFileContent.getContentAsText();
/*  56: 52 */       if (CharArrayUtil.indexOf(localCharSequence, "http://relaxng.org/ns/structure/1.0", 0) == -1)
/*  57:    */       {
/*  58: 52 */         FileIncludeInfo[] tmp33_30 = FileIncludeInfo.EMPTY;
/*  59: 52 */         if (tmp33_30 == null) {
/*  60: 52 */           throw new IllegalStateException(String.format("@NotNull method %s.%s must not return null", new Object[] { "org/intellij/plugins/relaxNG/model/resolve/RelaxIncludeProvider", "getIncludeInfos" }));
/*  61:    */         }
/*  62: 52 */         return tmp33_30;
/*  63:    */       }
/*  64: 53 */       localArrayList = new ArrayList();
/*  65: 54 */       NanoXmlUtil.parse(CharArrayUtil.readerFromCharSequence(paramFileContent.getContentAsText()), new RngBuilderAdapter(localArrayList));
/*  66:    */     }
/*  67: 55 */     else if (paramFileContent.getFileType() == RncFileType.getInstance())
/*  68:    */     {
/*  69: 56 */       localArrayList = new ArrayList();
/*  70: 57 */       paramFileContent.getPsiFile().acceptChildren(new RncElementVisitor()
/*  71:    */       {
/*  72:    */         public void visitElement(RncElement paramAnonymousRncElement)
/*  73:    */         {
/*  74: 60 */           paramAnonymousRncElement.acceptChildren(this);
/*  75:    */         }
/*  76:    */         
/*  77:    */         public void visitInclude(RncInclude paramAnonymousRncInclude)
/*  78:    */         {
/*  79: 65 */           String str = paramAnonymousRncInclude.getFileReference();
/*  80: 66 */           if (str != null) {
/*  81: 67 */             localArrayList.add(new FileIncludeInfo(str));
/*  82:    */           }
/*  83:    */         }
/*  84:    */       });
/*  85:    */     }
/*  86:    */     else
/*  87:    */     {
/*  88: 72 */       FileIncludeInfo[] tmp145_142 = FileIncludeInfo.EMPTY;
/*  89: 72 */       if (tmp145_142 == null) {
/*  90: 72 */         throw new IllegalStateException(String.format("@NotNull method %s.%s must not return null", new Object[] { "org/intellij/plugins/relaxNG/model/resolve/RelaxIncludeProvider", "getIncludeInfos" }));
/*  91:    */       }
/*  92: 72 */       return tmp145_142;
/*  93:    */     }
/*  94: 74 */     FileIncludeInfo[] tmp194_191 = ((FileIncludeInfo[])localArrayList.toArray(new FileIncludeInfo[localArrayList.size()]));
/*  95: 74 */     if (tmp194_191 == null) {
/*  96: 74 */       throw new IllegalStateException(String.format("@NotNull method %s.%s must not return null", new Object[] { "org/intellij/plugins/relaxNG/model/resolve/RelaxIncludeProvider", "getIncludeInfos" }));
/*  97:    */     }
/*  98: 74 */     return tmp194_191;
/*  99:    */   }
/* 100:    */   
/* 101:    */   private static class RngBuilderAdapter
/* 102:    */     extends NanoXmlUtil.IXMLBuilderAdapter
/* 103:    */   {
/* 104:    */     boolean isRNG;
/* 105:    */     boolean isInclude;
/* 106:    */     private final ArrayList<FileIncludeInfo> a;
/* 107:    */     
/* 108:    */     public RngBuilderAdapter(ArrayList<FileIncludeInfo> paramArrayList)
/* 109:    */     {
/* 110: 83 */       this.a = paramArrayList;
/* 111:    */     }
/* 112:    */     
/* 113:    */     public void startElement(String paramString1, String paramString2, String paramString3, String paramString4, int paramInt)
/* 114:    */       throws Exception
/* 115:    */     {
/* 116: 88 */       boolean bool = "http://relaxng.org/ns/structure/1.0".equals(paramString3);
/* 117: 89 */       if (!this.isRNG) {
/* 118: 90 */         if (!bool) {
/* 119: 91 */           stop();
/* 120:    */         } else {
/* 121: 93 */           this.isRNG = true;
/* 122:    */         }
/* 123:    */       }
/* 124: 96 */       this.isInclude = ((bool) && ("include".equals(paramString1)));
/* 125:    */     }
/* 126:    */     
/* 127:    */     public void addAttribute(String paramString1, String paramString2, String paramString3, String paramString4, String paramString5)
/* 128:    */       throws Exception
/* 129:    */     {
/* 130:101 */       if ((this.isInclude) && ("href".equals(paramString1))) {
/* 131:102 */         this.a.add(new FileIncludeInfo(paramString4));
/* 132:    */       }
/* 133:    */     }
/* 134:    */     
/* 135:    */     public void endElement(String paramString1, String paramString2, String paramString3)
/* 136:    */       throws Exception
/* 137:    */     {
/* 138:108 */       this.isInclude = false;
/* 139:    */     }
/* 140:    */   }
/* 141:    */ }



/* Location:           E:\idea\

 * Qualified Name:     org.intellij.plugins.relaxNG.model.resolve.RelaxIncludeProvider

 * JD-Core Version:    0.7.0.1

 */